package com.itheima.pinda.impl.transportline;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.pinda.DTO.entity.pojo.transportline.PdTransportLineType;
import com.itheima.pinda.feign.service.transportline.PdTransportLineTypeService;
import com.itheima.pinda.mapper.transportline.PdTransportLineTypeMapper;
import com.itheima.pinda.utils.CustomIdGenerator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import java.util.List;

/**
 * <p>
 * 线路类型表 服务实现类
 * </p>
 *
 * @author xy
 * @since 2021-11-15
 */
@Service
public class PdTransportLineTypeServiceImpl extends ServiceImpl<PdTransportLineTypeMapper, PdTransportLineType> implements PdTransportLineTypeService {

    @Autowired
    private CustomIdGenerator customIdGenerator;


    @Override
    public List<PdTransportLineType> findAdvance(String typeNumber, String name, String agencyType) {

        QueryWrapper<PdTransportLineType> wrapper = new QueryWrapper<>();
        wrapper.eq("type_number",typeNumber)
                .like("name",name)
                .like("start_agency_type",agencyType)
                .like("end_agency_type",agencyType);

        List<PdTransportLineType> transportLineTypeList = super.baseMapper.selectList(wrapper);

        return transportLineTypeList;
    }

    @Override
    public Integer insert(PdTransportLineType transportLineType) {

        if (ObjectUtils.isEmpty(transportLineType)){
            throw new NullPointerException("gfhjkdg");
        }

        int insert = super.baseMapper.insert(transportLineType);


        return insert;
    }

    @Override
    public Integer update(PdTransportLineType transportLineType) {
        if (ObjectUtils.isEmpty(transportLineType)){
            throw new NullPointerException("gfhjkdg");
        }

        int insert = super.baseMapper.updateById(transportLineType);


        return insert;
    }

    @Override
    public Integer disable(String id) {
        if (ObjectUtils.isEmpty(id)){
            throw new NullPointerException("gfhjkdg");
        }

        PdTransportLineType transportLineType = super.baseMapper.selectById(id);
//        super.baseMapper.upda
            transportLineType.setStatus(0);
        int i = super.baseMapper.updateById(transportLineType);


        return i;
    }
}
